/*
 * @Descripttion:
 * @version:
 * @Author: lehaixia
 * @Date: 2022-03-02 16:22:04
 * @LastEditors: lehaixia
 * @LastEditTime: 2022-03-07 09:56:05
 */
import { getDictList } from '@/api/dataDict'
export default {
  props: {
    orderData: {
      type: [String, Object],
      default: ''
    },
    dictData: {
      type: [String, Object],
      default: ''
    }
  },
  watch: {
    // orderData: {
    //   handler(val, oldVal) {
    //     this.initData()
    //   },
    //   immediate: true
    // }
  },
  computed: {
    orderId() {
      return (this.orderData && this.orderData.id) || ''
    }
  },
  created() {
    this.initData()
  },
  methods: {
    // 获取数据字典值对应的名称
    getDictName(dictType, dictCode) {
      let name = ''
      if (this.dictData && this.dictData[dictType]) {
        const index = this.dictData[dictType].findIndex(v => v.dictCode === dictCode)
        if (index > -1) {
          name = this.dictData[dictType][index].dictName
        }
      }
      return name
    },
    // 获取数据字典值对应的名称
    async getAsyncDictName(dictType, dictCode, appCode) {
      let name = ''
      const dictData = await getDictList({
        dictTypeCode: dictType, appCode, domainCode: 'marketing'
      })
      if (dictData && dictData.length) {
        const index = dictData.findIndex(v => v.dictCode === dictCode)
        if (index > -1) {
          name = dictData[index].dictName
        }
        console.log(index, dictCode)
      }
      console.log(name || dictCode)
      return name || dictCode
    }
  }
}
